package com.huike.controller.system;

import com.alibaba.druid.sql.visitor.functions.Char;
import com.huike.dto.DataScopeDto;
import com.huike.dto.SysRoleDto;
import com.huike.dto.SysRolePageDto;
import com.huike.result.Result;
import com.huike.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;


    /**
     * 角色列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Result listRole(SysRolePageDto dto) {
        log.info("角色列表:{}", dto);
        return roleService.listRole(dto);
    }

    @GetMapping("/all")
    public Result allMenuName() {
        log.info("获取菜单所有");
        return roleService.allMenuName();
    }

    @PostMapping("/save")
    public Result saveRole(@RequestBody SysRoleDto dto) {
        log.info("添加角色");
        return roleService.saveRole(dto);
    }

    /**
     * 回显
     */
    @GetMapping("/find/{id}")
    public Result findById(@PathVariable Long roleId) {
        return roleService.findById(roleId);
    }

    /**
     * 修改权限
     */
    @PutMapping("/update/dataScope")
    public Result updateDataScope(@RequestBody DataScopeDto dto) {
        return roleService.updateDataScope(dto);
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysRoleDto dto) {
        return roleService.update(dto);
    }

    @DeleteMapping("/del/{id}")
    public Result deleteById(@PathVariable("id") Long roleId) {
        return roleService.deleteById(roleId);
    }
}
